package com.hzp.lolnews.ui.discovery.view;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hzp.lolnews.R;
import com.hzp.lolnews.base.BaseRecyclerViewHolder;
import com.hzp.lolnews.bean.DiscoveryContent;
import com.hzp.lolnews.ui.novel.view.DetailShopActivity;

import java.util.List;

/**
 * Created by Administrator on 2016/10/21 0021.
 */
public class DiscoveryInnerContentAdapter extends RecyclerView.Adapter<BaseRecyclerViewHolder> {

    private List<DiscoveryContent.DataBean> mList;

    private Context mContext;

    public void setData(List<DiscoveryContent.DataBean> list, Context context) {
        this.mList = list;
        this.mContext = context;
        notifyDataSetChanged();
    }

    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_dis_inner_content, parent, false);
        return new BaseRecyclerViewHolder(view);
    }

    @Override
    public void onBindViewHolder(BaseRecyclerViewHolder holder, int position) {
        final DiscoveryContent.DataBean discoveryContent = mList.get(position);
        TextView tvPrice = holder.getView(R.id.dis_inner_tvPrice);
        Log.i("TAG", "onBindViewHolder:=====================tvprivce " + tvPrice);
        tvPrice.setText(discoveryContent.getPro_price());
        ImageView imageView = holder.getView(R.id.dis_inner_simpleDrawweeView);
        Glide.with(mContext).load(discoveryContent.getPro_pic()).placeholder(R.mipmap.ic_launcher).into(imageView);
        TextView tvTitle = holder.getView(R.id.dis_inner_tvTitle);
        tvTitle.setText(discoveryContent.getTitle());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, DetailShopActivity.class);
                intent.putExtra("getArticle_pic",discoveryContent.getPro_pic());
                intent.putExtra("getArticle_type_name",discoveryContent.getPro_subtitle());
                intent.putExtra("getArticle_format_date",discoveryContent.getType());
                intent.putExtra("getArticle_title",discoveryContent.getTitle());
                intent.putExtra("getArticle_comment",discoveryContent.getIs_spu());
                intent.putExtra("getArticle_filter_content",discoveryContent.getId());
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList != null ? mList.size() : 0;
    }
}
